import * as Service from '../services/userMsg';

export default {
  namespace: 'userMsg',
  state: {
  },
  reducers: {
    save(state, { payload: { data } }) {
      return { ...state, ...data };
    },

  },
  effects: {
    *fetch({ payload: { page, pathname } }, { call, put }) {
      const { data } = yield call(Service.fetch, { page, pathname });
      yield put({ type: 'save', payload: { data } });
    },
   
  },
  subscriptions: {
    setup({ dispatch, history }) {
      return history.listen(({ pathname, query }) => {
        if (pathname === '/UserMsg') {
          dispatch({ type: 'fetch', payload: { ...query, pathname } });
        }
      });
    },
  },
};